import pygame
import sys

#Iniciar pygame
pygame.init()

#Configurar la ventana
ancho = 1158
alto = 579
ventana = pygame.display.set_mode((ancho, alto))
VERDE = [0,200,0]
ventana.fill(VERDE)
pygame.display.set_caption("Cars of race")

mi_fondo = pygame.image.load("img/desmontable.jpg")
x,y = 0,0

ventana.blit(mi_fondo, [x,y])
pygame.display.flip()

coche = pygame.image.load("img/cocherecortado.tga")
print "ancho del coche =", coche.get_rect().w, "pixeles"
print "alto del coche = ",coche.get_rect().h, "pixeles"
x_coche,y_coche = 500,500
alto_coche = coche.get_rect().h
ancho_coche = coche.get_rect().w
ventana.blit(coche, [x_coche,y_coche])
pygame.display.flip()


while True:
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			pygame.quit()
			sys.exit()
        if event.type == pygame.KEYDOWN:
			if event.key == pygame.K_DOWN:
					ventana.blit(mi_fondo, [x,y])
					y_coche = y_coche + 10
					if y_coche + alto_coche  >= alto:
						y_coche = alto - alto_coche
					ventana.blit(coche, [x_coche,y_coche])
					pygame.display.flip()
			if event.key == pygame.K_UP:
					ventana.blit(mi_fondo, [x,y])
					y_coche = y_coche - 10
					if y_coche  <= 0:
						y_coche = 0
					ventana.blit(coche, [x_coche,y_coche])
					pygame.display.flip()
			if event.key == pygame.K_RIGHT:
					ventana.blit(mi_fondo, [x,y])
					x_coche = x_coche + 10
					if x_coche  <= 0:
						x_coche = 0
					ventana.blit(coche, [x_coche,y_coche])
					pygame.display.flip()
			if event.key == pygame.K_LEFT:
					ventana.blit(mi_fondo, [x,y])
					x_coche = x_coche -10
					if x_coche  >= 0:
						x_coche = 0
					ventana.blit(coche, [x_coche,y_coche])
					pygame.display.flip()
